import { reactive, ref, watch } from "vue";
import { transactionListApi } from "../../../api/a";
import { establishmentListApi } from "../../../api/userAudit";
import { delay } from "../../../utils/index";
export const useList = function () {
  const listRef = ref([]);
  const loadingRef = ref(false);
  const pageConfig = reactive({
    page: 1,
    size: 8,
    count: 0,
    type: 1,
  });

  (async function () {
    await delay(1000);
    transactionListApi(undefined, {
      ...pageConfig,
    }).then((resp) => {
      const { code, data } = resp;
      if (code === 200) {
        listRef.value = data.list;
        pageConfig.count = data.count;
      }
    });
  })();
  watch(pageConfig, async () => {
    loadingRef.value = true;
    await delay(1000);
    transactionListApi(undefined, {
      ...pageConfig,
    }).then((resp) => {
      const { code, data } = resp;
      if (code === 200) {
        listRef.value = data.list;
        pageConfig.count = data.count;
      }
      loadingRef.value = false;
    });
  });

  return {
    list: listRef,
    pageConfig,
    loading: loadingRef,
    handlePageChange(page) {
      pageConfig.page = page;
    },
  };
};
